;====================== MULTIFUNCTION DEMO PROJECT ====================== ; Roger Himka - Revised ; ; 1) GARAGE DOOR OPENER (GDO) operated PEDESTRIAN GATE ; Triggered by a Garage door opener (or a SPST momentary pushbutton) connected to GDOSWITCH ; click (approx 0.5 seconds from the GDO) down, click up. Once the GDO triggers the gate ; to DOWN, the PERIODIC DEMO input (A4) is diabled until the GDO triggers the gate UP ; and the gate raising sequence has been completed. ; Input A5 ; ; 2) PERIODIC DEMO ; Automatically goes through sequence, then is quiet for about two minutes ; Initiated by DEMOSWITCH being turnrd on (single pole single throw normally open). Once ; the DEMO mode has been selected, the GDO mode is disabled until input A4 goes low. ; Input A4 ; ; 3) SINGLE DEMO ; Automatically goes through sequence one time ; Initiated by DEMOSWITH activated for less than 10 seconds ; (must be off before the completion of the sequence) ; Input A4 ; ; ASSUMPTIONS ; Inputs A0, A1 are inactive (future potentiometer inputs), A2 through A5 are active low ; (switch bit reads CLEAR when switch is activated) ; Outputs C0 through C5 are active low ; Motor has external limit-stop switches used to limit gate travel ; External power switches will be used to de-activate Bell and/or GateMotor ;==================================================================== #include __config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _IESO_OFF & _FCMEN_OFF) #define ALLOUTPUTS 03Fh ; Outputs C6 and C7 not available on the 16F684 #define AUXBIT 020h ; AUX bit C5 #define BELLBIT 020h ; Sets the BELL bit C4 #define DELAYBEFOREDOWN 05h ; Half seconds from bell on to gates starting down (+1) #define DELAYTORAISEGATE 0Ch ; Half seconds to power gate up motor (+1) #define DEMODOWNTIME 10h ; Time (half seconds) gate will be down during demo #define DEMOMINREPLAYDELAY 06h ; Time (half seconds) before DEMOSWITCH can be reactivated #define DEMOQUIETTIME 0F0h ; Quiet time (240 half seconds) #define DEMOSWITCH 04h ; Input A4 Initiates periodic demo mode #define GATEDOWNBIT 02h ; C1 #define GATEUPBIT 01h ; C0 #define GATEBITS 03h ; Both Gate bits #define LAMPBITS 0Ch ; Both Lamp bits #define LAMPLEFTBIT 04h ; C2 #define LAMPRIGHTBIT 08h ; C5 #define MODEDEMO 01h #define MODEGDO 02h #define PUPBITS 066h ; Internal Pull ups on A1, A2, A4, A5 #define GDOSWITCH 05h ; Input A5 Initiates Pedestrian Gate position change #define TIMERHALFSECOND 08h #define TIMERQUARTERSECOND 04h cblock 0x20 Buf1 DCount1 Buf2 GateStatus Buf3 LightBellStatus Buf4 PortCVal ; The output control bits that have been issued to PORTC Buf7 RunTimer Buf8 DemoMode Buf9 DownTimeCount Buf10 QuietTimeCount endc org 0 nop Start: ;===================================================== ;-------- INITIALIZATIONS -------- ;-------- Page 1 Initialization -------- bsf STATUS,RP0 ; Select Register Bank 1 clrf ANSEL ; Make PortA all digital clrf TRISC ; Make PortC all (6) outputs movlw 3Fh movwf TRISA ; Make PortA all input bcf OPTION_REG,NOT_RAPU ; Enable pull-up enabling movlw PUPBITS movwf WPUA ; Enable pull-ups to selected bits movlw b'00000111' ; configure Timer0. Sourced from the Processor clock; movwf OPTION_REG ; Maximum Prescaler bcf STATUS,RP0 ; Un-Select Register Page 1 (Select Page 0) ;-------- Page 0 Initialization -------- ClearDemoMode: ;-------- Hardware Initialization -------- movlw 0FFh ; All outputs off movwf PORTC ;-------- Variable Initialization -------- movlw 0 movwf DemoMode ;=========================================================== ;-------- Main Program -------- WaitForActivation: ; Wait for switch activation btfss PORTA,GDOSWITCH goto BeginGDOMode btfsc PORTA,DEMOSWITCH goto WaitForActivation ;-------- Begin Demo mode BeginDemoMode: movlw MODEDEMO movwf DemoMode goto InitializeRunTime ;-------- Begin Garage Door Opener (GDO) mode BeginGDOMode: movlw MODEGDO movwf DemoMode WaitForRelease: call DelayQuarter ; Wait for switch pulse to expire btfss PORTA,GDOSWITCH goto WaitForRelease ;-------- Initialize Run Time -------- InitializeRunTime: movlw DELAYBEFOREDOWN movwf RunTimer ;-------- Set status for BELL on, LEFT LAMP off, RIGHT LAMP on -------- clrw iorlw BELLBIT iorlw LAMPLEFTBIT movwf PortCVal FlashLightsLoop1:;---------------------------------------------- ; Alternate the lights movf PortCVal,W xorlw LAMPBITS ; Alternate the lights movwf PortCVal ; Check if time to start gate down decfsz RunTimer,f goto OutputToPortC1 ; Initialize gate down timer movlw DEMODOWNTIME ; If mode is DEMO, time that gate will be down movwf DownTimeCount ; Start gate down movf PortCVal,W iorlw GATEDOWNBIT movwf PortCVal OutputToPortC1: xorlw 0FFh ; Complement W movwf PORTC ; Break delay into two parts to accomodate short pulse ; from garage door opener call DelayQuarter btfsc PORTA,GDOSWITCH goto NextQuarter ; GDO switch has initiated the raising of the gate call DelayQuarter ; Add in the remaining 1/4 delay goto BeginRaisingGate NextQuarter: call DelayQuarter ; If in GDO mode, check to see if the GDO switch has been activated movf DemoMode,W xorlw MODEGDO btfss STATUS,Z goto CheckDownTimeCount CheckGDOSwitch: btfsc PORTA,GDOSWITCH goto FlashLightsLoop1 ; IF in DEMO mode, continue to flashing lights until Down Tome Count expires CheckDownTimeCount: decfsz DownTimeCount,f goto FlashLightsLoop1 goto BeginRaisingGate ;---------------------------------------------- BeginRaisingGate: ; GDO or timeout has been activated to raise gate movlw DELAYTORAISEGATE ; Set expected time needed to raise gate movwf RunTimer movf PortCVal,W ; Turn off DOWN motor 1/2 second before starting UP motor andlw 0FCh ; Turn off both motor outputs xorlw LAMPBITS ; Alternate the lights movwf PortCVal xorlw 0FFh ; Complement W movwf PORTC call Delay ; Set alternate lamp and Gate UP movf PortCVal,W iorlw GATEUPBIT ; To turn on the gate-up motor movwf PortCVal FlashLightsLoop2:;---------------------------------------------- ; Alternate the lights movf PortCVal,W xorlw LAMPBITS ; Alternate the lights movwf PortCVal ; Check if time to finish gate up decfsz RunTimer,f goto Output2 movlw 0FFh ; Turn off all outputs movwf PORTC ; If GDO mode, go wait for the next switch activation movf DemoMode,W xorlw MODEGDO btfsc STATUS,Z goto WaitForActivation ; Wait for minimum time before next SINGLE DEMO movlw DEMOMINREPLAYDELAY movwf QuietTimeCount MinReplayDelayLoop: call Delay decfsz QuietTimeCount,f goto MinReplayDelayLoop ; DEMO mode - if switch is set, wait before next demo sequence, ; else wait for switch activation btfsc PORTA,DEMOSWITCH goto ClearDemoMode movlw DEMOQUIETTIME movwf QuietTimeCount QuietTimeLoop: call Delay decfsz QuietTimeCount,f goto QuietTimeLoop goto ClearDemoMode ; to start next demo sequence if DEMO switch still set Output2: movf PortCVal,W xorlw 0FFh ; Complement W movwf PORTC call Delay goto FlashLightsLoop2 ;==================================================== ;-------- Half second delay (approx.)-------- Delay: movlw TIMERHALFSECOND movwf DCount1 goto TimerLoop DelayQuarter: movlw TIMERQUARTERSECOND movwf DCount1 goto TimerLoop TimerLoop: btfss INTCON,T0IF ; Wait here until Timer0 rolls over goto TimerLoop bcf INTCON,T0IF ; flag must be cleared in software decfsz DCount1,f ; Decrement cycle count goto TimerLoop return ;==================================================================== end